package cloudeval.spec.metrics

import cn.edu.neu.vmmigeval.cloud.config.Migration
import cn.edu.neu.vmmigeval.cloud.entity.DataCenter
import cn.edu.neu.vmmigeval.cloud.entity.DataCenterBroker
import cn.edu.neu.vmmigeval.evaluation.Measure
import cn.edu.neu.vmmigeval.evaluation.VmMigrationCost

/**
 * Performance Degradation of Virtual Machines.
 *
 * @author yfwz100
 */
class PDV implements Measure {

    private List<Double> pdv = new ArrayList<>();

    @Override
    void process(int clock, DataCenterBroker dcb, DataCenter dc) {
        List<Migration> migrations = dc.vmAllocation.migrations;
        VmMigrationCost mc = new VmMigrationCost();
        Double costsOfThisClock = mc.getMigrationCost(migrations, dcb.vms.size());
        pdv.add(costsOfThisClock / dcb.vms.size());
    }

    @Override
    double getValue() {
        (pdv.sum() as double) / pdv.size()
    }

    @Override
    String toString() {
        return "PDV: ${getValue()}"
    }
}
